<?php
/**
 * Created by PhpStorm.
 * User: issac
 * Date: 2016/8/23
 * Time: 16:38
 */
namespace Common\Controller;
use Think\Controller;

abstract class BaseController extends Controller{

    public function ajaxMsg($status, $msg, $data=null) {

        if($data){

            echo json_encode(array(

                'status'=>$status,
                'msg'   =>$msg,
                'data'  =>$data

            ));

        }else {

            echo json_encode(array(

                'status'=>$status,
                'msg'   =>$msg

            ));

        }

        exit;

    }

    /**
     * 发送注册邮件
     * @param $address  （目标邮箱地址）
     * @param $title    （邮件标题）
     * @param $message  （邮件内容）
     * @return boolean
     * */
    public function sendMail($address,$title,$message){

        import("PHPMailer.phpmailer");
        $mail =new \PHPMailer();

        $mail->IsSMTP();
        $mail->CharSet ="UTF-8";
        $mail->AddAddress($address);
        $mail->Body =$message;
        $mail->From =C('MAIL_FORM_ADDRESS');
        $mail->FromName =C("MAIL_FORM_NAME");
        $mail->Subject =$title;
        $mail->Host =C("MAIL_HOST");
        $mail->SMTPAuth =true;
        $mail->Username =C("MAIL_USERNAME");
        $mail->Password =C("MAIL_PWD");

        return $mail->send();

    }

}